package com.yupi.yupicturebackend.manager.upload;

import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpUtil;
import com.yupi.yupicturebackend.exception.ErrorCode;
import com.yupi.yupicturebackend.exception.ThrowUtils;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.io.File;

@Service

public class UrlPictureUpload extends PictureUploadTemp{

    @Override
    protected void validPicture(Object inputSource) {
        String fileUrl= (String) inputSource;
        ThrowUtils.throwIf(fileUrl==null, ErrorCode.PARAMS_ERROR,"文件不能为空");
    }

    @Override
    protected String getOriginalFileName(Object inputSource) {
        String fileUrl= (String) inputSource;
        return FileUtil.mainName(fileUrl);
    }

    @Override
    protected void processFile(Object inputSource, File file) throws Exception {
        String fileUrl= (String) inputSource;
        //下载文件临时目录
        HttpUtil.downloadFile(fileUrl,file);

    }
}
